home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group02b.txt / 000168_icon-group-sender_Thu Dec 26 18:56:11 2002.msg < prev    next >
Internet Message Format  |  2003-01-02  |  5KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id gBR1rWM08248
  4.     for icon-group-addresses; Thu, 26 Dec 2002 18:53:32 -0700 (MST)
  5. Message-Id: <200212270153.gBR1rWM08248@baskerville.CS.Arizona.EDU>
  6. From: "Andrew Hamm" <ahamm@mail.com>
  7. X-Newsgroups: comp.lang.icon
  8. Subject: Re: Scanning question
  9. Date: Fri, 27 Dec 2002 11:29:34 +1100
  10. X-Priority: 3
  11. X-MSMail-Priority: Normal
  12. X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
  13. X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
  14. To: icon-group@cs.arizona.edu
  15. Errors-To: icon-group-errors@cs.arizona.edu
  16. Status: RO
  17.  
  18. ernobe wrote:
  19. > I wanted to scan thru several lines in a file searching for strings
  20. > that have been scanned out of another file.  So if an operation on a
  21. > specific line fails to produce results, I need to go to the next line
  22. > while keeping count of the number of strings that have been scanned
  23. > (I need to match the string itself and find its position in the file).
  24. > I had something like
  25. >
  26. > var := 1 # number of string
  27. > every line := read() do
  28. > (
  29. >     line ? while tab( upto( &letters ) ) do
  30. >         str := tab( many( &letters ) ) \ 1,
  31. >     count +:= 1,
  32. >     if count = var then
  33. >         write( file, str ),
  34. >     count := 0
  35. > )
  36.  
  37. OK - I can't see how your sample code does what you mention in the first
  38. paragraph, but you did say "something like" so I guess this is not trying to
  39. do what you want, but trying to understand what is happening?
  40.  
  41. > The problem is that if a line has no matches, I need to continue with
  42. > another line without setting the count back to zero.  'Every' is not
  43. > a loop structure so I can't put a 'next' in there before the count is
  44. > set back to zero.
  45.  
  46. Yes, "every" can be "next". Run this sample program:
  47.  
  48. procedure main()
  49.     j := 1
  50.     every i := 1 to 10 do
  51.     {
  52.         write(i, " ", j)
  53.         if i % 2 = 1 then next
  54.         j +:= 1
  55.     }
  56. end
  57.  
  58.  
  59. > I realize now that the scanning expression itself
  60. > was not the problem after all. I need to re-organize my program.
  61.  
  62. > if the 'then' clause fails in the conjunction, does the 'if'
  63. > clause itself fail?
  64.  
  65. Yes. Depending on the "if" condition, the "then" or the "else" part is
  66. executed. The outcome of the entire statement will be the outcome of the
  67. chosen "then" or "else" part. If the else part is missing, it is like a
  68. failure - effectively a missing else part generates zero results which will
  69. be a failure that will force backtracking.
  70.  
  71. In either situation, if the "then" or "else" part generates results, that is
  72. the result of the entire "if" statement. Note that the condition is never
  73. resumed - it is driven to produce ANY result so that the "then" or the
  74. "else" part can be selected but after that it is finished.
  75.  
  76. > If one backtracks into a conjunction,
  77. > does the whole thing resume, or just the final expression?
  78.  
  79. The whole conjunction. By the way, what you are using is actually called
  80. "mutual evaluation" although it is very similar to "conjunction".
  81. Conjunction is
  82.  
  83.     A & B & C ....
  84.  
  85. but you are using mutual evaluation:
  86.  
  87.     (A, B, C, ....)
  88.  
  89. In either case, backtracking can pass through the entire list of A B C as
  90. needed to produce a result. In both cases, the result of the expression is
  91. the result of the last part. Apart from the syntactical difference, mutual
  92. evaluation allows you to select which part you want the value of: for
  93. example
  94.  
  95.     2(A, B, C)
  96.  
  97. yields the values of B whenever it produces a result. A, B, and C need to
  98. produce a result in each case. For example, run this
  99.  
  100. procedure main()
  101.     every i := 2(1 to 3, 4 to 6, 7 to 9) do
  102.         write(i)
  103. end
  104.  
  105. And you'll see it write 4,4,4,5,5,5,6,6,6 three times ie 3*3*3 results.
  106.  
  107. Anyway, onto your specific problem. I'm not sure it's worth working on your
  108. sample code since it doesn't sound exactly like your goal. Your use of
  109. mutual evaluation is unusual but by no means wrong. Perhaps it's just me who
  110. doesn't use it very much like this. Actually, since I do use & very often to
  111. chain together expressions into one backtracking extravaganza, I suppose I
  112. do use it a lot ;-) Whatever the reason, if you still need help, please pass
  113. on your actual code so I (or others) can see your goal and where you might
  114. be going wrong.
  115. --
  116. There's nowt wrong wi' owt what mitherin' clutterbucks don't barly grummit!
  117. -
  118. Replies directly to this message will go to an account that may not be
  119. checked for a week or two. For more timely e-mail response, use (only
  120. in an emergency) ahamm sanderson net au with all the usual punctuation.
  121.  
  122.  
  123.